package yxy.game.pm2.chat.command;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.chat.module.ChatHandle;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ChatMessage;
import yxy.game.pm2.Result;

/** 聊天 注册聊天室 */
@MessageType(proto = Command.ChatRegister, classtype = ChatMessage.ChatRegisterRequest.class)
public class CMD_ChatRegister extends Command<ChatMessage.ChatRegisterRequest> {

	@Override
	public void execute(MessageSource messageSource, ChatMessage.ChatRegisterRequest request) {
		String playerCode = messageSource.getTag();

		ChatMessage.ChatRegisterResponse.Builder response = ChatMessage.ChatRegisterResponse.newBuilder();

		ChatHandle.register(playerCode);
		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, ChatMessage.ChatRegisterResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}